package nullInvader.Test;
import static org.junit.Assert.*;

import java.awt.Point;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

import nullInvader.Control.GameControl;
import nullInvader.Engine.*;

import org.junit.Before;
import org.junit.Test;

public class UnitTest {

    ConcurrentHashMap<Point, Zone> hashMap;
    ArrayList<Point> point;
    Point p ;
    Map map;
    Player player;
    GameControl gameControl;
    ArrayList<Tower> towerList;
    ArrayList<UnitInfo> unitInfo;

    /**
     * setUp method that creates the necessary objects for testing correctly
     */
    @SuppressWarnings("serial")
    @Before
    public void setUp() {
	point = new ArrayList<Point>();
	hashMap = new ConcurrentHashMap<Point, Zone>() {
	};
	point.add(new Point(13, 14));
	p = new Point(1,1);
	unitInfo = new ArrayList<UnitInfo>();
	towerList = new ArrayList<Tower>();
	map = new Map(hashMap, "test", 13, 0, p, point, unitInfo,
		towerList);
	gameControl = new GameControl(null);
	player = new Player(map, 11, gameControl);
	
    }

    @Test
    public void testUnitIntIntPoint() {
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	assertNotNull(u);
    }

    @Test
    public void testGetPrice() {
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	assertTrue(u.getPrice() ==100);
    }

    @Test
    public void testSetPosition() {
	Point p = new Point(1, 1);
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	assertTrue(p.equals(u.getPosition()));
	Point a = new Point(0, 1);
	assertFalse(a.equals(u.getPosition()));
	u.setPosition(a);
	assertTrue(a.equals(u.getPosition()));
    }

    @Test
    public void testSetNextPosition() {
	Point p = new Point(1, 1);
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	u.setNextPosition(p);
	assertTrue(p.equals(u.getPosition()));
    }

    @Test
    public void testGetPosition() {
	Point p = new Point(1, 1);
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	assertTrue(u.getPosition().equals(p));
    }

    @Test
    public void testKill() {
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	assertFalse(true == (u.isDead()));
	u.kill();
	assertTrue(true == (u.isDead()));
    }

    @Test
    public void testModifyHealth() {
	Unit u = null;
	u = new testUnitTDD(map.getStart(), player, 100);
	u.modifyHealth(-20);
	assertTrue(u.isDead());
    }

}
